package com.ruoyi.eqmonitor.smdtv.controller;

import java.util.List;

import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableSupport;
import com.ruoyi.eqmonitor.smdtv.domain.Smdtv11;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtv11Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

@Api(tags = "闸口")
@RestController
@RequestMapping("/smdtv11")
public class Smdtv11Controller extends BaseController{

    @Autowired
    private ISmdtv11Service smdtv11Service;

    /**
     * 获取闸口列表
     */
    @GetMapping("/list")
    public TableDataInfo<?> list(Smdtv11 smdtv11){
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        List<Smdtv11> list = smdtv11Service.selectSmdtv11List(smdtv11,(pageNum - 1) * pageSize,pageSize);
        return getDataTable2(list,smdtv11Service.getTotal(smdtv11));
    }

    /**
     * 获取全部闸口
     */
    @GetMapping("/all")
    public AjaxResult all(Smdtv11 smdtv11){
        return AjaxResult.success(smdtv11Service.selectSmdtv11List(smdtv11,null,null));
    }

    /**
     * 根据id查询闸口
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(smdtv11Service.selectSmdtv11ById(id));
    }

    /**
     * 新增闸口
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Smdtv11 smdtv11){
        return toAjax(smdtv11Service.save(smdtv11));
    }

    /**
     * 修改闸口
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Smdtv11 smdtv11){
        return toAjax(smdtv11Service.updateById(smdtv11));
    }

    /**
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "删除闸口", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(smdtv11Service.removeByIds(Arrays.asList(ids)));
    }

    /**
     * 导出闸口列表
     */
    @Log(title = "闸口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Smdtv11 smdtv11){
        List<Smdtv11> list = smdtv11Service.selectSmdtv11List(smdtv11,null,null);
        ExcelUtil<Smdtv11> util = new ExcelUtil<Smdtv11>(Smdtv11.class);
        util.exportExcel(response, list, "闸口数据");
    }

    /**
     * 根据水系名称获取闸口
     */
    @ApiOperation("根据水系名称获取闸口")
    @GetMapping("/getByName")
    public AjaxResult getByName(String gcm){
        return AjaxResult.success(smdtv11Service.getByName(gcm));
    }

    /**
     * 闸口树状图
     */
    @ApiOperation("树状图")
    @GetMapping(value = "/treeMap")
    public AjaxResult treeMap(){
        return AjaxResult.success(smdtv11Service.treeMap());
    }

}
